

const path = require('path');
const staticImg = path.join(__dirname, 'static');

function SensorbitUnoBlocks(Blockly) {
  var show_color = "#f59057";



   // 7219初始化
   Blockly.Blocks.microbit_matrix7219Init = {
    init:function(){
        this.setColour(show_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/24. 8x8.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_MATRIX7219)
        .appendField(Blockly.Msg.MICROBIT_DIN)
       .appendField(new Blockly.FieldDropdown([
        ['P15', "pin15"],
        ['P8', "pin8"],
       ]),"matrix_din")
       .appendField(Blockly.Msg.MICROBIT_CS)
       .appendField(new Blockly.FieldDropdown([
        ['P2', "pin2"],
        ['P1', "pin1"],
       ]),"matrix_cs")
       .appendField(Blockly.Msg.MICROBIT_CLK)
       .appendField(new Blockly.FieldDropdown([
        ['P13', "pin13"],
        ['P0', "pin0"],
       ]),"matrix_sda")
       this.appendDummyInput("")
       .appendField(Blockly.Msg.MICROBIT_MATRIX7219INTENSITY)
       .appendField(new Blockly.FieldDropdown([
        ['7', "7"],
        ['1', "1"],
        ['2', "2"],
        ['3', "3"],
        ['4', "4"],
        ['5', "5"],
        ['6', "6"],
        ['8', "8"],
        ['9', "9"],
        ['10', "10"],
        ['11', "11"],
        ['12', "12"],
        ['13', "13"],
        ['14', "14"],
        ['15', "15"],
       ]),"initIntensity")
        this.setPreviousStatement(true,null);
        this.setNextStatement(true,null);
        this.setTooltip('');
    }
};

// 7219 点显示亮度
Blockly.Blocks.microbit_matrix7219SetPixel = {
    init:function(){
        this.setColour(show_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/24. 8x8.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_MATRIX7219SETPIXEL)
        .appendField(new Blockly.FieldDropdown([
            ['0', "0"],
            ['1', "1"],
            ['2', "2"],
            ['3', "3"],
            ['4', "4"],
            ['5', "5"],
            ['6', "6"],
            ['7', "7"],
           ]),"matrixX")
        // this.appendValueInput("matrixX", Number)
        .appendField(Blockly.Msg.MICROBIT_MATRIX7219X)
        .appendField(new Blockly.FieldDropdown([
            ['0', "0"],
            ['1', "1"],
            ['2', "2"],
            ['3', "3"],
            ['4', "4"],
            ['5', "5"],
            ['6', "6"],
            ['7', "7"],
           ]),"matrixY")
        // this.appendValueInput("matrixY", Number)
        .appendField(Blockly.Msg.MICROBIT_MATRIX7219Y)
        .appendField(new Blockly.FieldDropdown([
            ['7', "7"],
            ['1', "1"],
            ['2', "2"],
            ['3', "3"],
            ['4', "4"],
            ['5', "5"],
            ['6', "6"],
            ['8', "8"],
            ['9', "9"],
            ['10', "10"],
            ['11', "11"],
            ['12', "12"],
            ['13', "13"],
            ['14', "14"],
            ['15', "15"],
           ]),"intensity")
        // this.appendValueInput("intensity", Number)
        .appendField(Blockly.Msg.MICROBIT_MATRIX7219INTENSITY)
        this.setPreviousStatement(true,null);
        this.setNextStatement(true,null);
        this.setTooltip('');
    }
};

// 7219 点阵图像 
Blockly.Blocks.microbit_matrix7219Draw = {
    init:function(){
        this.setColour(show_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/24. 8x8.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_MATRIX7219DRAM)
        this.appendDummyInput('').appendField(new Blockly.LatticeAdapter(), 'lattice');
        this.setPreviousStatement(true,null);
        this.setNextStatement(true,null);
        this.setTooltip('');
    }
};
      

    return Blockly;
}

module.exports = SensorbitUnoBlocks;

